package com.evildog.workspace.invest.application.controller;

import com.evildog.workspace.common.result.PagedResult;
import com.evildog.workspace.common.object.PageQuery;
import java.util.List;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import com.evildog.workspace.common.result.ResultGenerator;
import com.evildog.workspace.common.result.Result;
import com.evildog.workspace.invest.application.model.BudgetPageParam;
import com.evildog.workspace.invest.application.model.BudgetListParam;
import com.evildog.workspace.invest.application.model.BudgetParam;
import com.evildog.workspace.invest.application.vo.BudgetPageVO;
import com.evildog.workspace.invest.application.vo.BudgetListVO;
import com.evildog.workspace.invest.application.vo.BudgetVO;
import com.evildog.workspace.invest.application.bo.BudgetBO;
import com.evildog.workspace.invest.application.bo.BudgetPageBO;
import com.evildog.workspace.invest.application.bo.BudgetListBO;
import com.evildog.workspace.invest.application.convert.BudgetConvert;
import com.evildog.workspace.invest.application.service.BudgetService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * <p>
 * budget Controller
    预算
 * </p>
 *
 * @author evildog
 * @since 2020-08-06
 */
@RestController
@RequestMapping("/budgets")
@AllArgsConstructor
@Api(tags = "budget相关接口")
public class BudgetController {

    private BudgetService budgetService;

    @PostMapping
    @ApiOperation(value = "添加接口")
    public Result<Boolean> save(@RequestBody BudgetParam budgetParam) {
        return ResultGenerator.status(budgetService.save(BudgetConvert.INSTANCE.convert(budgetParam)));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除接口")
    public Result<Boolean> removeById(@PathVariable("id") Long id) {
        return ResultGenerator.status(budgetService.removeById(id));
    }

    @DeleteMapping("/batch-remove")
    @ApiOperation(value = "批量删除接口")
    public Result<Boolean> removeByIds(@RequestParam("ids") List<Integer> ids) {
        return ResultGenerator.status(budgetService.removeByIds(ids));
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "更新接口")
    public Result<Boolean> updateById(@PathVariable("id") Long id,@RequestBody BudgetParam budgetParam) {
        return ResultGenerator.status(budgetService.updateById(id, BudgetConvert.INSTANCE.convert(budgetParam)));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "查询详情接口")
    public Result<BudgetVO> getById(@PathVariable("id") Long id) {
        BudgetBO budgetBO = budgetService.getDetailById(id);
        return ResultGenerator.success(BudgetConvert.INSTANCE.convert(budgetBO));
    }

    @GetMapping("/page")
    @ApiOperation(value = "表分页查询接口")
    public Result<PagedResult<BudgetPageVO>> getPageList(BudgetPageParam budgetPageParam, PageQuery query){
        PagedResult<BudgetPageBO> budgetPageBO = budgetService.getPageList(
                        query,
                        QueryConditionUtils.getQueryCondition(budgetPageParam),
                        BudgetConvert.INSTANCE.convert(budgetPageParam));
        return ResultGenerator.success(BudgetConvert.INSTANCE.convert(budgetPageBO));
    }

    @GetMapping
    @ApiOperation(value = "表List查询接口")
    public Result<List<BudgetListVO>> getList(BudgetListParam budgetListParam){
        List<BudgetListBO> budgetListBO = budgetService.getList(
                        QueryConditionUtils.getQueryCondition(budgetListParam),
                        BudgetConvert.INSTANCE.convert(budgetListParam));
        return ResultGenerator.success(BudgetConvert.INSTANCE.convertVoList(budgetListBO));
    }

}